package com.scott.itcast.thread.lesson01;
public class TraditionalThread {
	
	public static void main(String[] args) {
		
		//第1个线程
		//new的是Thread的子类  1条线程
		Thread thread = new Thread(){
			@Override
			public void run() {
				//覆盖父类的run方法
				while(true){
					try {
						//当前线程先休息500毫秒
						Thread.sleep(500);
						String name = Thread.currentThread().getName();
						System.out.println("1: "+name);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				
			}
		};
		thread.start();
		
		//第2个线程
		Thread thread2 = new Thread(new Runnable(){
			
			public void run() {
				//覆盖父类的run方法s
				while(true){
					try {
						//当前线程先休息500毫秒
						Thread.sleep(500);
						String name = Thread.currentThread().getName();
						System.out.println("2: "+name);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		});
		
		thread2.start();
		
		//第3个线程
		new Thread(new Runnable(){
			//在构造方法中传实现了Runnable接口的对象
			public void run() {
				while(true){
					try {
						//当前线程先休息500毫秒
						Thread.sleep(500);
						String name = Thread.currentThread().getName();
						System.out.println("Runnable: "+name);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
			
		}){
			//子类覆盖父类的方法
			public void run() {
				while(true){
					try {
						//当前线程先休息500毫秒
						Thread.sleep(500);
						String name = Thread.currentThread().getName();
						System.out.println("Thread: "+name);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			};
		}.start();
	}
	

}
